using System;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;

namespace OurWedding1.Models
{ 
    public class ExpenseSumRepository : IExpenseSumRepository
    {
        readonly WeddingEntities _context = new WeddingEntities();

        public IQueryable<ExpenseSum> All
        {
            get { return _context.ExpenseSums; }
        }

        public IQueryable<ExpenseSum> AllIncluding(params Expression<Func<ExpenseSum, object>>[] includeProperties)
        {
            return includeProperties.Aggregate<Expression<Func<ExpenseSum, object>>, IQueryable<ExpenseSum>>(_context.ExpenseSums, (current, includeProperty) => current.Include(includeProperty));
        }

        public ExpenseSum Find(int id)
        {
            return _context.ExpenseSums.Find(id);
        }

        public void InsertOrUpdate(ExpenseSum expensesum)
        {
            if (expensesum.ExpenseSumId == default(int)) {
                // New entity
                _context.ExpenseSums.Add(expensesum);
            } else {
                // Existing entity
                _context.Entry(expensesum).State = EntityState.Modified;
            }
        }

        public void Delete(int id)
        {
            var expensesum = _context.ExpenseSums.Find(id);
            _context.ExpenseSums.Remove(expensesum);
        }

        public void Save()
        {
            _context.SaveChanges();
        }

        public void Dispose() 
        {
            _context.Dispose();
        }
    }

    public interface IExpenseSumRepository : IDisposable
    {
        IQueryable<ExpenseSum> All { get; }
        IQueryable<ExpenseSum> AllIncluding(params Expression<Func<ExpenseSum, object>>[] includeProperties);
        ExpenseSum Find(int id);
        void InsertOrUpdate(ExpenseSum expensesum);
        void Delete(int id);
        void Save();
    }
}